<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
<!--
.stylethem {
	color: #000 !important;
	font-weight: bold !important;
	font-size: 24px !important;
}
.stylethem1 {font-weight: bold !important;}
-->
</style>
<script language="JavaScript" type="text/javascript" src="ckeditor/ckeditor.js"></script>
<script language="JavaScript" type="text/javascript" src="ckeditor/sample.js"></script>
</head>
<body>
<?php
	$id=$_REQUEST["id"];
	$result=mysql_query("SELECT * FROM doitac WHERE madoitac = $id");
	$row=mysql_fetch_assoc($result);
		$link = $row['link'];
		$ha = $row["hinhanh"];
		$hinhanh=$row["hinhanh"];
		$hinhanh="../images/doitac/".$hinhanh;
?>

    <form action="<?php echo "?thamso=suadoitac&id=$id"; ?>" method="post" enctype="multipart/form-data" name="form1">
      <table width="400" border="0" align="center" cellpadding="3" cellspacing="3">
        <tr align="center" bgcolor="#333333">
          <td colspan="2"><span class="stylethem">Đối tác công ty</span></td>
        </tr>
        <tr bgcolor="#F2F2F2">
            <td width="20%">
                <strong>Link: </strong>
            </td>
            <td width="80%">
                <input type='text' name='txttsp' size='50' value="<?php	echo $link;	?>"/>
            </td>
        </tr>
         <tr bgcolor="#F2F2F2">
        	<td width='20%'><strong>Hình ảnh: </strong></td>
        	<td width='80%'> 
            	<input type='file' name='hinh' style="width:100px" /><br />
                <?php  echo"<img src=$hinhanh width='100px' height='100px'  ></img>";?>
          	</td>
        </tr>
        <tr align="center" bgcolor="#CFCFCF">
        	<td width='20%'>&nbsp;</td>
			<td width='80%'><input type="submit" class="nut_chapnhan" value="Cháº¥p nháº­n" name="them"></td>
        </tr>  
      </table>
    </form>
</body>
</html>
<?php
function upload_anh(){
		$hinh=$_FILES["hinh"]["name"];
		$duongdan_upload_anh="../images/doitac/$hinh";
		chong_90($hinh);
		move_uploaded_file($_FILES["hinh"]["tmp_name"],$duongdan_upload_anh);
		return $hinh;
	}
	function ktfile($tenfile)
	{
		$pattern='#.+\.(gif|jpg|png)$#i';
		if(preg_match($pattern,$tenfile)==1)
		{
    		return 1;
		}
		else
		{
    		return 0;
		}
	}
	if(isset($_POST["them"]))
	{
		$hinh=upload_anh();
		if(ktfile($_FILES["hinh"]["name"])==1)
				{	
					$hinh=$_FILES["hinh"]["name"];
				}		
		$link = $_POST['txttsp'];
		if ($hinh == "")
		$hinh = $ha;
		else chong_90($hinh);
		$sql = "UPDATE `doitac` SET `link` = '$link', `hinhanh` = '$hinh'
		WHERE `madoitac` = $id";
		$result = mysql_query($sql);
		if($result)
		{
			echo "<script>alert('Sửa thành công');</script>";
			echo "<script>window.location=('?thamso=dsdoitac');</script>";
		}
		
	}
?>